package com.multimedia.scala.euler
/*
A Pythagorean triplet is a set of three natural numbers, a  b  c, for which,

a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.

c = 1000 - a - b
1000000 - 2000*a - 2000*b + a*a  + 2*a*b + b*b = a*a + b*b
500000 - 1000*a - 1000*b + a*b = 0
500000-1000*b = 1000*a-a*b
a = (500000-1000*b)/(1000-b)
 */
object Asd9 {
  def pythagor(x: Double, y: Double): Double = Math.sqrt(x*x + y*y)
  def c(x1: Double, x2: Double) = 1000 - x1 - x2
  def a(x2: Double) = (500000 - 1000 * x2)/(1000 - x2)
  def test(x1: Double, x2: Double, x3: Double): Boolean = (x1>0)&&(x2>0)&&(x1 + x2 + x3)==1000&&(x1*x1==x2*x2+x3*x3)

  def main(args : Array[String]) : Unit = {
    (1 to 998).map(_.toDouble).foreach(x3 =>{
        var x2 = a(x3)
        var x1 = c(x2, x3)
        if (test(x1, x2, x3))
        	println(x1 + "," + x2 + "," + x3 + ":" + x1*x2*x3)
    })
    println(BigInt(425)*BigInt(375)*BigInt(200))
  }
}
